package com.css.dzj.zfjg.modules.complaintinfo.service.Impl;

import com.css.dzj.zfjg.common.util.ServiceUtil;
import com.css.dzj.zfjg.modules.complaintinfo.entity.JgLhjgComplaintInfoEntity;
import com.css.dzj.zfjg.modules.complaintinfo.entity.QJgLhjgComplaintInfoEntity;
import com.css.dzj.zfjg.modules.complaintinfo.mapper.JgLhjgComplaintInfoMapper;
import com.css.dzj.zfjg.modules.complaintinfo.service.JgLhjgComplaintInfoService;
import com.querydsl.core.QueryResults;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 企业投诉信息接口实现类
 * @author wt
 * @date 2020\2\19 0019
 */
@Service
public class JgLhjgComplaintInfoServiceImpl implements JgLhjgComplaintInfoService {

    @Autowired
    private JgLhjgComplaintInfoMapper cMapper;

    @Autowired
    private JPAQueryFactory jpaQueryFactory;

    @Autowired
    private ServiceUtil serviceUtil;

    /**
     * 添加企业投诉信息
     */
    @Override
    @Transactional
    public void add(JgLhjgComplaintInfoEntity jgLhjgComplaintInfo) {
        try {
            cMapper.save(jgLhjgComplaintInfo);
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 修改企业投诉信息
     */
    @Override
    @Transactional
    public void update(JgLhjgComplaintInfoEntity jgLhjgComplaintInfo) {

    }

    /**
     * 通过id查询企业投诉信息
     */
    @Override
    public JgLhjgComplaintInfoEntity findById(String id) {
        return cMapper.findById(id).get();
    }

    /**
     * 分页查询企业投诉信息
     */
    @Override
    public QueryResults<JgLhjgComplaintInfoEntity> queryPage(Pageable pageable) {
        QJgLhjgComplaintInfoEntity qComp = QJgLhjgComplaintInfoEntity.jgLhjgComplaintInfoEntity;
        QueryResults<JgLhjgComplaintInfoEntity> compResults = jpaQueryFactory.selectFrom(qComp)
                .offset(pageable.getOffset())
                .limit(pageable.getPageSize())
                .fetchResults();
        return compResults;
    }

    /**
     * 物理删除企业投诉信息
     */
    @Override
    @Transactional
    public void delete(JgLhjgComplaintInfoEntity jgLhjgComplaintInfo) {
        try {
            cMapper.delete(jgLhjgComplaintInfo);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * 根据任务编码查询企业信息
     * @param taskNo
     * @return
     */
    @Override
    public JgLhjgComplaintInfoEntity findByTaskNo(String taskNo) {
        QJgLhjgComplaintInfoEntity q = QJgLhjgComplaintInfoEntity.jgLhjgComplaintInfoEntity;
        return jpaQueryFactory.selectFrom(q).where(q.taskNo.eq(taskNo)).fetchOne();
    }
}
